﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.MarketUI.assets {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Classes.*;
    import flash.text.*;
    import Engine.*;

    public class CardUtil {

        static function scaleToFit(_arg1:DisplayObject, _arg2:DisplayObject):Number{
            var _local3:Number = 1;
            var _local4:Number = 1;
            if (_arg1.width > _arg2.width){
                _local3 = (_arg2.width / _arg1.width);
            };
            if (_arg1.height > _arg2.height){
                _local4 = (_arg2.height / _arg1.height);
            };
            return (Math.min(_local3, _local4));
        }
        public static function loadIcon(_arg1:Item, _arg2:DisplayObject):void{
            var loader:* = null;
            var data:* = _arg1;
            var asset:* = _arg2;
            var url:* = Global.gameSettings.getImageByName(data.name, "icon");
            loader = LoadingManager.load(url, function (_arg1:Event):void{
                var _local2:*;
                var _local3:*;
                if (((loader) && (loader.content))){
                    _local2 = (asset["icon"] as MovieClip);
                    _local3 = CardUtil.scaleToFit(loader.content, _local2);
                    loader.content.scaleX = (loader.content.scaleY = _local3);
                    Utilities.removeAllChildren(_local2);
                    _local2.addChild(loader.content);
                };
            });
        }
        public static function populatePriceButton(_arg1:Item, _arg2:DisplayObject):void{
            var _local3:* = _arg2["priceButton"];
            if (_arg1.cash > 0){
                _local3.coinsSymbol.visible = false;
            } else {
                _local3.cashSymbol.visible = false;
            };
            var _local4:Number = ((_arg1.cash)>0) ? _arg1.cash : _arg1.cost;
            if (_local4 > 0){
                _local3.mouseEnabled = (_local3.mouseChildren = false);
                _local3.priceTextField.text = String(_local4);
                EmbeddedArt.updateFont(_local3.priceTextField);
            } else {
                _local3.visible = false;
            };
        }
        public static function indexOfByCardName(_arg1:Array, _arg2:String):int{
            var _local3:int;
            while (_local3 < _arg1.length) {
                if (_arg1[_local3].name == _arg2){
                    return (_local3);
                };
                _local3++;
            };
            return (-1);
        }
        public static function populateFields(_arg1:Object, _arg2:DisplayObject):void{
            var _local3:String;
            var _local4:TextField;
            for (_local3 in _arg1) {
                if (_arg2.hasOwnProperty(_local3)){
                    if ((_arg2[_local3] is TextField)){
                        _local4 = _arg2[_local3];
                        _local4.text = _arg1[_local3];
                        _local4.mouseEnabled = false;
                        EmbeddedArt.updateFont(_local4);
                    };
                };
            };
        }
        public static function localizeBuildTime(_arg1:Number):String{
            return (ZLoc.t("Dialogs", "CatalogBuildTime", {time:localizeTimeLeft(_arg1)}));
        }
        private static function formatNumber(_arg1:Number):String{
            var _local2:Number = Math.abs((_arg1 - Math.round(_arg1)));
            if (_local2 < 0.05){
                return (Math.round(_arg1).toFixed(0));
            };
            return (_arg1.toFixed(1));
        }
        public static function formatTimeHours(_arg1:Number):String{
            var _local2:Number;
            var _local3:Number = (_arg1 / (60 * 60));
            _local2 = (_local3 - Math.floor(_local3));
            _local3 = Math.floor(_local3);
            var _local4:Number = (_local2 * 60);
            _local2 = (_local4 - Math.floor(_local4));
            _local4 = Math.floor(_local4);
            var _local5:Number = (_local2 * 60);
            _local2 = (_local5 - Math.floor(_local5));
            _local5 = Math.floor(_local5);
            var _local6:String = ((_local3 < 10)) ? ("0" + _local3) : ("" + _local3);
            var _local7:String = ((_local4 < 10)) ? ("0" + _local4) : ("" + _local4);
            var _local8:String = ((_local5 < 10)) ? ("0" + _local5) : ("" + _local5);
            if ((((_arg1 < 0)) || (isNaN(_arg1)))){
                return ("00:00");
            };
            if (_local3 > 0){
                return ((((((_local6 + "H:") + _local7) + "M:") + _local8) + "S"));
            };
            return (((_local7 + ":") + _local8));
        }
        public static function formatTime(_arg1:Number):String{
            var _local2:Number;
            var _local3:Number = (_arg1 / ((60 * 60) * 24));
            _local2 = (_local3 - Math.floor(_local3));
            _local3 = Math.floor(_local3);
            var _local4:Number = (_local2 * 24);
            _local2 = (_local4 - Math.floor(_local4));
            _local4 = Math.floor(_local4);
            var _local5:Number = (_local2 * 60);
            _local2 = (_local5 - Math.floor(_local5));
            _local5 = Math.floor(_local5);
            var _local6:Number = (_local2 * 60);
            _local2 = (_local6 - Math.floor(_local6));
            _local6 = Math.floor(_local6);
            var _local7:String = ((_local3 < 10)) ? ("0" + _local3) : ("" + _local3);
            var _local8:String = ((_local4 < 10)) ? ("0" + _local4) : ("" + _local4);
            var _local9:String = ((_local5 < 10)) ? ("0" + _local5) : ("" + _local5);
            var _local10:String = ((_local6 < 10)) ? ("0" + _local6) : ("" + _local6);
            if ((((_arg1 < 0)) || (isNaN(_arg1)))){
                return ("00:00");
            };
            if (_local4 > 0){
                return (((((((_local7 + ":") + _local8) + ":") + _local9) + ":") + _local10));
            };
            return (((_local9 + ":") + _local10));
        }
        public static function localizeTimeLeftLanguage(_arg1:Number):String{
            if (_arg1 > 1.083){
                return (ZLoc.t("Dialogs", "TT_CatalogTimeLeftDays", {time:formatNumber(_arg1)}));
            };
            var _local2:int = int((_arg1 * 24));
            if ((((_local2 >= 23)) && ((_local2 <= 25)))){
                return (ZLoc.t("Dialogs", "TT_CatalogTimeLeftOneDay"));
            };
            if (_local2 > 1){
                return (ZLoc.t("Dialogs", "TT_CatalogTimeLeftHours", {time:Math.round(_local2).toFixed(0)}));
            };
            var _local3:int = int(((_arg1 * 24) * 60));
            if (_local3 >= 58){
                return (ZLoc.t("Dialogs", "TT_CatalogTimeLeftOneHour"));
            };
            return (ZLoc.t("Dialogs", "TT_CatalogTimeLeftMinutes", {time:_local3}));
        }
        public static function localizeTimeLeft(_arg1:Number):String{
            if (_arg1 > 1.083){
                return (ZLoc.t("Dialogs", "CatalogTimeLeftDays", {time:formatNumber(_arg1)}));
            };
            var _local2:int = int((_arg1 * 24));
            if ((((_local2 >= 23)) && ((_local2 <= 25)))){
                return (ZLoc.t("Dialogs", "CatalogTimeLeftOneDay"));
            };
            if (_local2 > 1){
                return (ZLoc.t("Dialogs", "CatalogTimeLeftHours", {time:Math.round(_local2).toFixed(0)}));
            };
            var _local3:int = int(((_arg1 * 24) * 60));
            if (_local3 >= 58){
                return (ZLoc.t("Dialogs", "CatalogTimeLeftOneHour"));
            };
            return (ZLoc.t("Dialogs", "CatalogTimeLeftMinutes", {time:_local3}));
        }

    }
}//package Display.MarketUI.assets 
